package com.netty;

import java.sql.Time;
import java.util.concurrent.TimeUnit;

public class DeadLock {
    private final static String LOCK1 = "LOCK1";
    private final static String LOCK2 = "LOCK2";
    public static void A() {
        new Thread(()->{
            synchronized (LOCK1){
                try {
                    TimeUnit.SECONDS.sleep(2);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (LOCK2){
                    System.out.println(Thread.currentThread().getName() + "进来了");
                }
            }
        },"线程A").start();
    }
    public static void B(){
        new Thread(()->{
            synchronized (LOCK2){
                synchronized (LOCK1){
                    System.out.println(Thread.currentThread().getName() + "进来了");
                }
            }
        },"线程B").start();
    }

    public static void main(String[] args) {
        A();
        B();
    }
}
